<template>
    <view>
        <view class="container">
            <view class="orderlist" v-for="(item, index) in list" :key="index">
                <view class="content">
                    <view class="jobinfo">
                        <view class="jobleft">
                            <view>{{ item.notecount }}</view>
                            <view>投递简历</view>
                        </view>
                        <view class="line"></view>

                        <view class="jobright">
                            <view class="jobtitle">
                                <view>{{ item.jobtitle }}</view>
                                <view @tap="editCompanyjob" :data-id="item.id"><image src="/static/imgs/icon/edit.png" /></view>
                            </view>
                            <view>人数:{{ item.num }} | 薪资:{{ item.money }}</view>
                            <view>
                                创建:{{ item.createtime }}
                                <text style="color: red">({{ item.ischeck == 1 ? '审核通过' : '待审核' }} | {{ item.status == 1 ? '已上架' : '已下架' }} )</text>
                            </view>
                        </view>
                    </view>

                    <view class="payitem">
                        <view v-if @tap="toMatchnote" :data-id="item.id" :data-ischeck="item.ischeck">匹配</view>

                        <!-- <view hidden="" bindtap='formSubmit' data-id="{{item.id}}" data-ischeck="{{item.ischeck}}" >分享</view> -->

                        <block v-if="item.status == 0">
                            <view v-if @tap="cancleJob" :data-id="item.id">下架</view>
                        </block>
                        <block v-else>
                            <view v-if @tap="upJob" :data-id="item.id">上架</view>
                        </block>

                        <view v-if @tap="editCompanyjob" :data-id="item.id">编辑</view>
                    </view>
                </view>
            </view>
        </view>

        <view class="weixinmao-float">
            <view class="weixinmao-foot">
                <view class="footer" @tap="addcompanyjob">添加招聘职位</view>
            </view>
        </view>

        <view class="imagePathBox" v-if="maskHidden != false">
            <image :src="imagePath" class="shengcheng"></image>
            <button class="baocun" @tap="baocun">保存相册，分享到朋友圈</button>
        </view>

        <view v-if="maskHidden != false" class="mask"></view>
        <view class="canvas-box">
            <canvas style="width: 375px; height: 667px; position: fixed; top: 9999px" canvas-id="mycanvas" />
        </view>
    </view>
</template>

<script>
import { Company } from '../../model/company-model.js';
var company = new Company();
export default {
    data() {
        return {
            /* 生成二维码参数 */
            img: '../../imgs/icon/gobg.png',

            wechat: '../../imgs/icon/wechat.png',
            quan: '../../imgs/icon/quan.png',
            code: 'E7AI98',
            inputValue: '',
            maskHidden: false,
            name: '',
            touxiang: '',

            code: 'E7A93C',
            /* 生成二维码参数 */ list: '',
            imagePath: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onShow: function (options) {
        this.onShowClone3389(options);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {},
    methods: {
        /**
         * 生命周期函数--监听页面加载
         */
        onShowClone3389: function (options) {
            var that = this;
            uni.setNavigationBarTitle({
                title: '职位管理'
            });
            company.checkLogin(() => {
                var ctoken = uni.getStorageSync('ctoken');
                if (ctoken) {
                    var params = {
                        ctoken: ctoken
                    };
                    company.companyjob((data) => {
                        that.setData({
                            list: data.joblist
                        });
                    }, params);
                } else {
                    uni.navigateTo({
                        url: '/pages/companylogin/index'
                    });
                }
            });
        },

        createNewImg: function () {
            var that = this;
            var context = uni.createCanvasContext('mycanvas');
            context.setFillStyle('#ffe200');
            context.fillRect(0, 0, 375, 667);
            var path = '../../imgs/icon/gobg.png';
            //将模板图片绘制到canvas,在开发工具中drawImage()函数有问题，不显示图片
            //不知道是什么原因，手机环境能正常显示
            context.drawImage(path, 0, 0, 375, 667);
            var path1 = that.touxiang;
            console.log(path1, 'path1');
            //将模板图片绘制到canvas,在开发工具中drawImage()函数有问题，不显示图片
            //var path2 = "../../imgs/icon/txquan.png";
            //var path3 = "../../imgs/icon/heise.png";

            var path4 = '/static/imgs/icon/wenziBg.png';
            var path5 = '../../imgs/icon/wenxin.png';

            // context.drawImage(path2, 126, 186, 120, 120);

            var name = that.name;
            //绘制名字
            context.setFontSize(24);
            context.setFillStyle('#333333');
            context.setTextAlign('center');
            context.fillText(name, 185, 340);
            context.stroke();

            //绘制左下角文字背景图
            context.drawImage(path4, 25, 520, 184, 82);
            context.setFontSize(12);
            context.setFillStyle('#333');
            context.setTextAlign('left');
            context.fillText('进入小程序查看海量职位', 35, 540);
            context.stroke();
            context.setFontSize(12);
            context.setFillStyle('#333');
            context.setTextAlign('left');
            context.fillText(',高端职位正在等着', 35, 560);
            context.stroke();
            context.setFontSize(12);
            context.setFillStyle('#333');
            context.setTextAlign('left');
            context.fillText('你来哦~', 35, 580);
            context.stroke();
            //绘制右下角扫码提示语

            context.drawImage(that.myqrcodefile, 243, 495, 100, 100);
            context.drawImage(path5, 248, 598, 90, 25);
            //绘制头像
            context.arc(186, 246, 50, 0, 2 * Math.PI); //画出圆
            context.strokeStyle = '#ffe200';
            context.clip(); //裁剪上面的圆形
            context.drawImage(path1, 136, 196, 100, 100); // 在刚刚裁剪的园上画图
            context.draw();
            //将生成好的图片保存到本地，需要延迟一会，绘制期间耗时

            setTimeout(function () {
                uni.hideToast();
                that.drawAfter();
                that.setData({
                    maskHidden: true
                });
            }, 200);
        },

        //点击保存到相册
        baocun: function () {
            var that = this;
            uni.saveImageToPhotosAlbum({
                filePath: that.imagePath,
                success(res) {
                    uni.showModal({
                        content: '图片已保存到相册，赶紧晒一下吧~',
                        showCancel: false,
                        confirmText: '好的',
                        confirmColor: '#333',
                        success: function (res) {
                            if (res.confirm) {
                                console.log('用户点击确定');
                                /* 该隐藏的隐藏 */
                                that.setData({
                                    maskHidden: false
                                });
                            }
                        },
                        fail: function (res) {
                            console.log(11111);
                        }
                    });
                }
            });
        },

        addcompanyjob: function () {
            var ctoken = uni.getStorageSync('ctoken');
            var params = {
                ctoken: ctoken
            };
            company.companycenter((data) => {
                if (data.totaljobnum < 1) {
                    uni.showModal({
                        title: '提示',
                        content: '发布职位数量不足',
                        showCancel: false
                    });
                    return;
                } else {
                    uni.navigateTo({
                        url: '/pages/addcompanyjob/index'
                    });
                }
            }, params);
        },

        editCompanyjob: function (e) {
            var id = e.currentTarget.dataset.id;
            uni.redirectTo({
                url: '/pages/editcompanyjob/index?id=' + id
            });
        },

        toMatchnote: function (e) {
            var id = e.currentTarget.dataset.id;
            var ischeck = e.currentTarget.dataset.ischeck;
            if (ischeck == 0) {
                uni.showModal({
                    title: '提示',
                    content: '该职位未审核通过',
                    showCancel: false
                });
                return;
            } else {
                uni.navigateTo({
                    url: '/pages/matchnote/index?id=' + id
                });
            }
        },

        topPaytopjob: function (e) {
            var that = this;
            var id = e.currentTarget.dataset.id;
            var companyid = uni.getStorageSync('companyid');
            var params = {
                companyid: companyid,
                id: id
            };
            uni.showModal({
                title: '提示',
                content: '您的操作将会消耗置顶1次？',
                success: function (res) {
                    if (res.confirm) {
                        company.topJob((data) => {
                            if (data.status == 0) {
                                uni.showModal({
                                    title: '提示',
                                    content: data.msg,
                                    showCancel: false,
                                    success: function () {
                                        that.onShowClone3389({});
                                    }
                                });
                            } else {
                                uni.showToast({
                                    title: data.msg,
                                    icon: 'none',
                                    duration: 2000
                                });
                            }
                        }, params);
                    }
                }
            });
        },

        cancleJob: function (e) {
            var that = this;
            var id = e.currentTarget.dataset.id;
            var companyid = uni.getStorageSync('companyid');
            var params = {
                companyid: companyid,
                id: id
            };
            uni.showModal({
                title: '下架',
                content: '确认下架？',
                success: function (res) {
                    if (res.confirm) {
                        company.cancleJob((data) => {
                            that.onShowClone3389({});
                        }, params);
                    }
                }
            });
        },

        upJob: function (e) {
            var that = this;
            var id = e.currentTarget.dataset.id;
            var companyid = uni.getStorageSync('companyid');
            var params = {
                companyid: companyid,
                id: id
            };
            uni.showModal({
                title: '上架',
                content: '确认上架？',
                success: function (res) {
                    if (res.confirm) {
                        company.upJob((data) => {
                            that.onShowClone3389({});
                        }, params);
                    }
                }
            });
        }
    }
};
</script>
<style>
/* pages/companyjob/index.wxss */

.container {
    background-color: #f5f5f5;
    min-height: 100%;
}
.container .orderlist {
    width: 100%;
    display: flex;
    flex-direction: column;
    background: #fff;
    margin-top: 10rpx;
}
.container .orderlist .orderid {
    border-bottom: 1rpx solid #efefef;
    padding-top: 20rpx;
    padding-bottom: 20rpx;
    padding-left: 20rpx;
    font-size: 0.8rem;
    width: 720rpx;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
}
.container .orderlist .orderid image {
    width: 50rpx;
    height: 50rpx;
}

.container .orderlist .content {
    font-size: 0.8rem;
    border-bottom: 1rpx solid #efefef;
}
.container .orderlist .content .item {
    padding-top: 16rpx;
    padding-bottom: 16rpx;
    padding-left: 20rpx;
    border-bottom: 1rpx dotted #efefef;
    display: flex;
    flex-direction: row;
}
.syscompany {
    width: 180rpx;
    height: 60rpx;
    line-height: 60rpx;
    text-align: center;
    margin-right: 20rpx;
    border-radius: 5rpx;
    background: #44b549;
    font-size: 0.6rem;
    color: #fff;
    margin-left: 230rpx;
}
.container .orderlist .content .payitem {
    width: 720rpx;
    display: flex;
    flex-direction: row;
    justify-content: flex-end;
    padding-bottom: 20rpx;
    padding-top: 20rpx;
    margin-left: 20rpx;
}
.container .orderlist .content .payitem view {
    width: 120rpx;
    height: 60rpx;
    line-height: 60rpx;
    text-align: center;
    margin-right: 20rpx;
    border-radius: 5rpx;
    border: 1rpx solid #f5f5f5;
    font-size: 0.6rem;
    color: #666666;
}
/*
.container .orderlist .content .payitem view:nth-child(1){

  background: #44b549;

}
.container .orderlist .content .payitem view:nth-child(2){

  background: #3274e5;

}

.container .orderlist .content .payitem view:nth-child(3){

  background: #e64340;

}

*/

.weixinmao-float {
    height: 150rpx;
}
.weixinmao-foot {
    display: flex;
    justify-content: center;
    flex-direction: row;
    position: fixed;
    z-index: 999;
    left: 0;
    bottom: 0;
    width: 100%;

    background: #fff;
    padding-top: 10rpx;
    padding-bottom: 30rpx;
}

.weixinmao-foot view {
    color: #fff;
    height: 100rpx;
    line-height: 100rpx;
    font-size: 0.9rem;
    width: 100%;
    border-radius: 0rpx;
    background: #e64340;
    text-align: center;
}

.intro {
    padding: 10rpx;
    font-size: 0.8rem;
}

.jobinfo {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    border-bottom: 1rpx solid #f5f5f5;
}
.jobinfo .jobleft {
    width: 200rpx;
    height: 200rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.jobinfo .jobleft view:nth-child(1) {
    font-weight: 600;
    font-size: 1.5rem;
}

.jobinfo .jobleft view:nth-child(2) {
    color: #666666;
    font-size: 0.7rem;
}

.jobinfo .jobleft {
    width: 230rpx;
    height: 230rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.jobinfo .jobright {
    width: 500rpx;
    height: 230rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.jobinfo .jobright .jobtitle {
    font-weight: 600;
    font-size: 1.2rem;
    display: flex;
    flex-direction: row;
}
.jobinfo .jobright .jobtitle image {
    width: 45rpx;
    height: 45rpx;
    margin-left: 30rpx;
}

.jobinfo .jobright view:nth-child(2) {
    color: #666666;
    font-size: 0.7rem;
}

.jobinfo .jobright view:nth-child(3) {
    color: #666666;
    font-size: 0.7rem;
}

.jobinfo .jobright view:nth-child(4) {
    color: #666666;
    font-size: 0.7rem;
}
.line {
    height: 230rpx;
    border: 1rpx dotted #f5f5f5;
}

.imagePathBox {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
}
.shengcheng {
    width: 80%;
    height: 80%;
    position: fixed;
    top: 50rpx;
    left: 50%;
    margin-left: -40%;
    z-index: 10;
}
.baocun {
    display: block;
    width: 80%;
    height: 80rpx;
    padding: 0;
    line-height: 80rpx;
    text-align: center;
    position: fixed;
    bottom: 50rpx;
    left: 10%;
    background: #ffe200;
    color: #333;
    font-size: 32rpx;
    border-radius: 44rpx;
}
button[class='baocun']::after {
    border: 0;
}
</style>
